<?php
include_once ("../Login/databaseconnection.php");
$q=$_GET["q"];
$hint="";
$name=explode(",",$q);
$nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $School_Id=$row['School_Id'];
}
if($q!="")
{
$maxid=mysql_query("SELECT max(Lab_Id) as maxId FROM lab WHERE School_Id='$School_Id'");
while($rowid=mysql_fetch_array($maxid))
{
$m_Id=$rowid['maxId'];
if($m_Id=="")
{
$L_Id="L0001";
}
else
{
$inum=substr("$m_Id",1);
$inn=($inum+1);
$r=(strlen($inum)-strlen($inn));
$L_Id='L';
if(strlen($inn)<strlen($inum))
{
for($i=0;$i<(strlen($inum)-strlen($inn));$i++)
{
$L_Id=$L_Id.'0';
}
$L_Id=$L_Id.$inn;
}
else
{
$L_Id=$L_Id.$inn;
}
}
}
$hint=$hint."<input type='text' name='Lab_Id' id='Lab_Id' value='$L_Id' readonly='readonly'/>";
}
if($hint=="")
{
$response="<input type='text' name='Lab_Id' id='Lab_Id'/>";
}
else
{
$response=$hint;
}
echo $response;
?>